﻿
namespace HttpServer.MVC.Rendering.Spark
{
    /// <summary>
    /// The generic SparkView class holds information needed to render the model to HTML.
    /// </summary>
    /// <remarks>
    /// This is identical to the generic SparkView written by 
    /// Louis DeJardin in his Spark.Web.Mvc integration project.
    /// </remarks>
    public abstract class SparkView<TModel> : SparkView where TModel : class
    {
        private SparkDataDictionary<TModel> _ViewData;

        public new SparkDataDictionary<TModel> ViewData
        {
            get
            {
                if (_ViewData == null)
                    SetViewData(new SparkDataDictionary<TModel>());
                return _ViewData;
            }
            set { SetViewData(value); }
        }

        public TModel Model
        {
            get { return ViewData.Model; }
        }

        protected override void SetViewData(SparkDataDictionary viewData)
        {
            _ViewData = new SparkDataDictionary<TModel>(viewData);
            base.SetViewData(_ViewData);
        }
    }
}
